package com.jdz.gxq.info.admin.fund.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.jdz.gxq.info.admin.fund.bo.Fund;
import com.jdz.gxq.info.admin.fund.form.EditFundForm;
import com.jdz.gxq.info.admin.fund.service.FundService;
import com.jdz.gxq.info.common.action.CommonAction;

public class SaveFundAction extends CommonAction {

	private FundService fundService = null;
	 
	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {
		
		EditFundForm editFundForm = (EditFundForm) form;
		
		Fund fund = editFundForm.getFund();
		
		// fund名重复验证(其他后台逻辑验证也类似处理)
		if (!fundService.checkFundName(fund, 2)) {
			ActionMessages messages = new ActionMessages();
			messages.add("fund.projectName", new ActionMessage("error.fundNameExisted"));
			addErrors(request, messages);
			return mapping.getInputForward();
		}
		
		fund.setModifiedBy(getUserId(request));
		
		fundService.updateFund(fund);
		
		return mapping.findForward("success");
	}

	public void setFundService(FundService fundService) {
		this.fundService = fundService;
	}
}

